<?php


namespace App\Http\Controllers\android\api;


use App\Http\Controllers\android\service\SnService;
use App\Http\Controllers\android\validate\sn;
use App\Http\Controllers\utils\ToolUtil;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class SnApi
{



    //记录重启
    public function restart(Request $request)
    {
        $sn = ToolUtil::filterStr($request->input('sn'));
        if(empty($sn)){
            return ToolUtil::returnJson(-100,'sn参数不能为空！');
        }
        $info = DB::table('t_admin_sn')->where(['value'=>$sn])->select(['restart_count'])->first();
        if($info){
            $data['update_time'] = time();
            $data['restart_count'] = $info['restart_count']+1;
            DB::table('t_admin_sn')->where(['value'=>$sn])->update($data);
            DB::table('sn_restore_restart')->insert(['sn'=>$sn,'add_time'=>time(),'type'=>1]);
            return ToolUtil::returnJson(200,'成功');
        }
        return ToolUtil::returnJson(-300, '设备未激活');
    }

    public function bindSn(Request $request){
        $param = $request->all();
        $data = sn::bindSn($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::bindSn($param);
    }

    public function getSnInfo(Request $request){
        $param = $request->all();
        $data = sn::getSnInfo($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::getSnInfo($param);
    }

    public function updateAdminSn(Request $request){
        $param = $request->all();
        $data = sn::updateAdminSn($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::updateAdminSn($param);
    }

    public function uploadAppUseInfo(Request $request){
        $param = $request->all();
        $data = sn::uploadAppUseInfo($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::uploadAppUseInfo($param);
    }

    public function querySnAppStart(Request $request){
        $param = $request->all();
        $data = sn::querySnAppStart($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::querySnAppStart($param);
    }

    public function querySnJump(Request $request){
        $param = $request->all();
        $data = sn::querySnJump($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::querySnJump($param);
    }

    public function uploadScreenshot(Request $request){
        $param = $request->all();
        $data = sn::uploadScreenshot($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::uploadScreenshot($param);
    }

    public function getTimeControl(Request $request){
        $param = $request->all();
        $data = sn::getTimeControl($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::getTimeControl($param);
    }

    public function getScreenshot(Request $request){
        $param = $request->all();
        $data = sn::getScreenshot($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::getScreenshot($param);
    }

    public function getBanner(){
        return SnService::getBanner();
    }

    public function getUserAvatarInfo(Request $request){
        $param = $request->all();
        $data = sn::getUserAvatarInfo($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::getUserAvatarInfo($param);
    }

    public function saveSnUid(Request $request){
        $param = $request->all();
        $data = sn::saveSnUid($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::saveSnUid($param);
    }

    public function deleteSnUid(Request $request){
        $param = $request->all();
        $data = sn::deleteSnUid($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::deleteSnUid($param);
    }

    public function getSnUid(Request $request){
        $param = $request->all();
        $data = sn::getSnUid($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::getSnUid($param);
    }

    public function getBatch(Request $request){
        $param = $request->all();
        $data = sn::getBatch($param);
        if($data){
            return ToolUtil::returnJson(401,$data[0]);
        }
        return SnService::getBatch($param);
    }


    
}